<?php

/**
 * Created by PhpStorm.
 * User: evan
 * Date: 16/9/1
 * Time: 下午6:12
 */
class Log extends MY_Admin_Controller
{
    /**
     * 登陆日志
     */
    public function login()
    {
        $page = intval($this->input->get_post('page'));
    	$page = $page ? $page : 1;
    	
    	$uid = intval($this->input->get_post('uid'));
    	
    	$where = array();
    	
    	if($uid){
    		$where['uid'] = $uid;
    	}
    	
        $this->load->model('user/Model_user_login_log','login_log');
        $total_rows = $this->login_log->count($where);
        
        //分页
        $this->load->library('pagination');
         
        $config['total_rows'] = $total_rows;
        $config['per_page'] = 20;
        $config['base_url'] = '/user/Log/login';
         
        $this->pagination->initialize($config);
        $show_page = $this->pagination->create_links();
        
        $offset = ($page-1) * $config['per_page'];
        $list = $this->login_log->lists($offset,  $config['per_page'], $where);

         $data = array(
            'infoAll'   => $list,
         	'show_page'   => $show_page,
         	'total_rows'  => $config['total_rows'],
        );
        $this->load->view('admin/user/log/login',$data);
    }

    /**
     * 删除登陆日志
     */
    public function delete()
    {
        $response = array('code' => '0', 'msg' => '操作成功');

        do {
            $lid = (int)$this->input->get_post('lid');

            if (!$lid)
            {
                $response = error(200000);
                break;
            }

            $this->load->model('user/model_user_login_log', 'login');

            $res = $this->login->delete(array('lid' => $lid));

            if (!$res)
            {
                $response = error(10080);
                break;
            }
        }while (false);


        $this->json_output($response);
    }
}